package com.nus.servlets;

import com.nus.beans.User;
import com.nus.database.UserDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 9/24/12
 * Time: 7:47 PM
 * To change this template use File | Settings | File Templates.
 */
public class ViewUsersServlet extends AbstractServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        Connection connection = getUserDatabaseConnection(request);
        UserDBManager infoManager = new UserDBManager(connection);



        List<User> usersList = infoManager.loadUsers();
        request.setAttribute("usersList", usersList);

        infoManager.close();

        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/view_users.jsp");
        dispatcher.forward(request, response);

    }
}
